 #include<bits/stdc++.h>
 using namespace std;
 long long a[100001],c[100],n;
 long long score()
 {
     int i,j,sum=0;
     for(i=1;i<=n;i++)
     {
         for(j=i-1;j>=1;j--)
         {
             if(c[i]==c[j]&&a[i]==a[j])
             {
                 sum+=a[i];
                 break;
             }
         }
     }
     return sum;
 }
 int main()
 {
     freopen("color.in","r",stdin);
     freopen("color.out","w",stdout);
     long long T,i,j,num,ans;
     cin>>T;
     while(T>0)
     {
         ans=0;
         memset(c,sizeof(c),0);
         T--;
         cin>>n;
         for(i=1;i<=n;i++) cin>>a[i];
         while(c[n+1]==0)
         {
             ans=max(ans,score());
             c[1]+=1;
            for(i=1;i<=n;i++)
            {
                if(c[i]==2)
                {
                    c[i]-=2;
                    c[i+1]+=1;
                }
                else break;
            }
         }
         cout<<ans<<endl;
     }
 }
